<template>
  <div class="greetings">
    <h1 class="green">{{ msg }}</h1>
    <h3 v-if="isShow" @click="sendE">
      You’ve successfully created a project with
      <a href="https://vitejs.dev/" target="_blank" rel="noopener">Vite</a> +
      <a href="https://vuejs.org/" target="_blank" rel="noopener">Vue 3</a>. What's next?
    </h3>
    透传属性:{{ $attrs }}
  </div>
</template>

<script setup lang="ts">
  import { ref, onMounted } from 'vue'

  defineOptions({
    inheritAttrs: true
  })

  onMounted(() => {
    console.log('组件触发了')
  })

  // 接收参数
  defineProps<{
    msg: string
  }>()

  let isShow = ref(true)
  function changeShow() {
    isShow.value = !isShow.value
  }

  // 发送参数
  const emit = defineEmits<{
    (e: 'aheihei', id: number): void
    (e: 'update', value: string): void
  }>()
  function sendE() {
    emit('aheihei', 555)
  }

  // 暴露自身方法
  defineExpose({
    changeShow
  })
</script>

<style scoped>
  h1 {
    font-weight: 500;
    font-size: 2.6rem;
    position: relative;
    top: -10px;
  }

  h3 {
    font-size: 1.2rem;
  }

  .greetings h1,
  .greetings h3 {
    text-align: center;
  }

  @media (min-width: 1024px) {
    .greetings h1,
    .greetings h3 {
      text-align: left;
    }
  }
</style>
